package com.tenton.servlet;

import com.tenton.pojo.City;
import com.tenton.pojo.Province;
import com.tenton.service.CityService;
import com.tenton.service.Impl.CityServiceImpl;
import com.tenton.service.Impl.ProvinceServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Date: 2021/1/14
 * @Author: Tenton
 * @Description: 城市
 */
@WebServlet(name = "CityServlet" , urlPatterns = "/cityServlet")
public class CityServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式，防止乱码
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        //省份Code
        String provinceCode = request.getParameter("provinceCode");
        //用户名
        String userName = request.getParameter("userName");
        //密码
        String password = request.getParameter("password");
        //邮箱
        String email = request.getParameter("email");
        CityService cityService = new CityServiceImpl();
        //通过省份Code查询城市
        List<City> cityList = cityService.listCityByProvinceCode(provinceCode);
        request.setAttribute("cityList",cityList);
        request.setAttribute("provinceCode",provinceCode);
        request.setAttribute("userName",userName);
        request.setAttribute("password",password);
        request.setAttribute("email",email);
        request.getRequestDispatcher("/initServlet").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
